import { PropsWithChildren } from 'react';
import { useEffect, FC, useState } from 'react';
import { eightActiveArr } from '../../config/defaultParam'
import { View, Text, Icon, Input, Image } from '@tarojs/components'
import './index.less'
import { getReservePlatformList } from '@api/myIndex.ts'



const Index: FC<PropsWithChildren> = () => {
  const [reserve, setReserve] = useState([])
  useEffect(() => {
    // 任何你需要在组件挂载时执行的副作用
    const fetchReserveData = async () => {
      try {
        const result = await getReservePlatformList()
        if (result.code === 200) {
          // setReserve(result);
          console.log('result', result)
        }
      } catch (error) {
        console.error('获取预约列表失败',);
      }
    };
    // fetchReserveData()
  }, []);

  const gotoReserve = (linkUrl: string) => {
    wx.navigateToMiniProgram({
      shortLink: linkUrl,
      envVersion: 'release',
      success(res) {
        console.log('res', res)
      }
    })
  }

  return (
    <View className='reserveBox'>
      <View className="reserve-list-group">
        {eightActiveArr.map((item, index) => {
          const { name, number, imgUrl, open, linkUrl } = item
          return <View className='list' key={index}>
            <Image className='left-content' src={imgUrl} mode='aspectFit' />
            <View className='right-content'>
              <View className='left'>
                <Text className='textOne'>{name}</Text>
                <Text className='textTwo'>葫芦娃{number}号</Text>
              </View>
              <View className='right'>
                {
                  open ? <View className='goto' onClick={() => gotoReserve(linkUrl)}>去预约</View> :
                    <View className='no_active'>无活动</View>
                }
              </View>
            </View>
          </View>
        })}
      </View>
    </View>
  );
};

export default Index;